/**
 * 基础的游戏类
 * 属性： 宽度 高度、横坐标、纵坐标、横向速度、纵向速度、对应的dom元素
 */
class Rectangle {
    constructor(width,height,x,y,vx,vy,dom){
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.vx = vx;
        this.vy = vy;
        this.dom = dom;
        this.render();
    }

    /**
     * 渲染
     */
    render(){
        this.dom.style.width = this.width + "px";
        this.dom.style.height = this.height + "px";
        this.dom.style.left = this.x + "px";
        this.dom.style.top = this.y + "px";
    }
    onMove(){

    }
    /**
     *  在duration时间下物体移动
     * @param {number} duration  间隔
     */
    move(duration){
        this.x += this.vx * duration;
        this.y += this.vy * duration;
        if(this.onMove) this.onMove();
        this.render();
    }
}